<template>
  <el-card>
    <el-form :inline="true" :model="formInline" class="demo-form-inline" :disabled="isShowtime">
      <el-form-item label="一级标题">
        <el-select v-model="category1Id" placeholder="请选择">
          <el-option :label="c1.name" :value="c1.id" v-for="c1 in categoryStore.category1List" :key="c1.id" />
        </el-select>
      </el-form-item>

      <el-form-item label="二级标题">
        <el-select v-model="category2Id" placeholder="请选择">
          <el-option :label="c2.name" v-for="c2 in categoryStore.category2List" :key="c2.id" :value="c2.id" />
        </el-select>
      </el-form-item>

      <el-form-item label="三级标题">
        <el-select v-model="category3Id" placeholder="请选择">
          <el-option :label="c3.name" v-for="c3 in categoryStore.category3List" :key="c3.id" :value="c3.id" />
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script lang="ts">
export default {
  name: "CategorySelector",
  props: {
    isShowtime: {
      type: Boolean,
    },
  },
}
</script>
<script lang="ts" setup>
import { computed, onMounted, reactive } from "vue"
import { useCategoryListStore } from "@/stores/categoryList"
const categoryStore = useCategoryListStore()
const formInline = reactive({
  user: "",
  region: "",
})

// let isShow = defineProps(["isShow"])
// console.log("aa", isShow.isShow)
// 一级导航ID
// 计算属性,对一级导航的id进行类似侦听,一旦id发生变化,就会执行set,然后我们可以巧妙地利用set函数,发送获取二级导航的数据内容
const category1Id = computed({
  get() {
    return categoryStore.category1Id as number
  },
  set(val: number) {
    // 当一级导航的id发生变化就执行这个函数
    // 获取二级导航的数据
    // console.log(val)
    categoryStore.getCategory2ListData(val)
  },
})
// 二级导航ID
const category2Id = computed<number>({
  get() {
    return categoryStore.category2Id as number
  },
  set(val) {
    categoryStore.getCategory3ListData(val)
  },
})
//  三级导航ID
const category3Id = computed<number>({
  get() {
    return categoryStore.category3Id as number
  },
  set(val) {
    categoryStore.setCategory3Id(val)
  },
})
onMounted(() => {
  // 一级分类不需要参数,页面一挂载完成就要获取到
  categoryStore.getCategory1ListData()
  // console.log(categoryStore.category1List)
})
</script>
<style></style>
